﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace E1_eMart
{
    public partial class Main : System.Web.UI.MasterPage
    {
        public TaiKhoan gTaiKhoan = new TaiKhoan();
        protected int loaiTaiKhoan = -1;
        protected LoaiSanPham allCat = new LoaiSanPham();
        protected List<LoaiSanPham> lspList = new List<LoaiSanPham>();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["username"] != null)
            {
                gTaiKhoan = (TaiKhoan)Session["username"];
                loaiTaiKhoan = (int)gTaiKhoan.MaLoaiTaiKhoan;
            }
        }

        protected void catSelector_Init(object sender, EventArgs e)
        {
            DataClasses1DataContext edata = new DataClasses1DataContext();
            
            allCat.MaLoaiSanPham = 0;
            allCat.TenLoaiSanPham = "All Categories";

            lspList.Add(allCat);

            var itemQuery = from sp in edata.LoaiSanPhams
                             select sp;
            lspList.AddRange(itemQuery.ToList());

            catSelector.DataSource = lspList;
            catSelector.DataTextField = "TenLoaiSanPham";
            catSelector.DataBind();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string key = input.Text.Trim();
            string catID = catSelector.SelectedIndex.ToString();

            Response.Redirect("search_detail.aspx?key=" + key + "&catID=" + catID);
        }      
    }
}